package com.hsgc.controller;

import com.github.pagehelper.PageHelper;
import com.hsgc.dto.ResponseDTO;
import com.hsgc.model.Category;
import com.hsgc.model.CategoryQuery;
import com.hsgc.servce.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/category")
//@CrossOrigin //跨域访问解决不是同源的问题
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @GetMapping
    public List<Category> select(CategoryQuery query){
//        PageHelper.startPage(1,3);
     return  categoryService.select(query);
    }

    @PostMapping
    public Integer insert(@RequestBody Category category){
        return categoryService.insert(category);
    }
    @PutMapping
    public Integer update(@RequestBody Category category){
        return categoryService.update(category);
    }
    @DeleteMapping
    public Integer delete(Integer id){
        return categoryService.updateStatus(id);
    }

//    @GetMapping
//    public ResponseDTO select(CategoryQuery query){
//        List<Category> select = categoryService.select(query);
//        return  ResponseDTO.success(select);
//    }
}
